<?php

/**
 * update actions.
 *
 * @package    s-test
 * @subpackage update
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class updateActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
   
  }
  public function executeMigration(sfWebRequest $request){
    chdir(sfConfig::get('sf_root_dir'));

    $this->has_errors = false;
    //On va créer les fichiers de migrations
    $generate_migrations_diff_task = new sfDoctrineGenerateMigrationsDiffTask($this->dispatcher, new sfFormatter());
    //puis recréer les classes de bases
    $build_all_class_task = new sfDoctrineBuildTask($this->dispatcher, new sfFormatter());
    //puis migrer
    $migrate_task = new sfDoctrineMigrateTask($this->dispatcher, new sfFormatter());

    try{
        $generate_migrations_diff_task->run();
    }   catch(Exception $e){
        $this->has_errors = true;
        $this->error_title = 'Generate Migrations Diff '.$e->getFile().'( Line :'.$e->getLine().' )';
        $this->error = $e->getMessage();
        return;
    }try{
        $build_all_class_task->run(array(), array("all-classes"));

    }    catch(Exception $e){
        $this->has_errors = true;
        $this->error_title = 'Build All Classes '.$e->getFile().'( Line :'.$e->getLine().' )';
        $this->error = $e->getMessage();
        return;
    }
    try{
        $migrate_task->run();
    }catch(Exception $e){
        $this->has_errors = true;
        $this->error_title = 'Migrate '.$e->getFile().'( Line :'.$e->getLine().' )';
        $this->error = $e->getMessage();
        return;
    }

  }
}
